import { defineStore } from 'pinia'

export const useSidebarStore = defineStore('sidebar', {
  state: () => ({
    isCollapsed: false
  }),
  
  actions: {
    toggleCollapse() {
      this.isCollapsed = !this.isCollapsed
      // 保存到本地存储，在页面刷新后保持状态
      localStorage.setItem('sidebarStatus', this.isCollapsed ? '1' : '0')
    },
    
    // 从本地存储初始化状态
    initFromStorage() {
      const status = localStorage.getItem('sidebarStatus')
      if (status !== null) {
        this.isCollapsed = status === '1'
      }
    }
  }
}) 